package ${controllerPackage};

import ${apiPackage}.${apiName};
import ${modelPackage}.${modelName};
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
<#if enableSwagger3>
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
</#if>
<#if enableLombok>
import lombok.RequiredArgsConstructor;
</#if>

/**
* ${tableComment} API
* @author ${author}
* @since ${date}
*/
@RestController
@RequestMapping("/${camelTableName?uncap_first}")
<#if enableLombok>
@RequiredArgsConstructor
</#if>
<#if enableSwagger3>
@Tag(name = "${tableComment} API")
</#if>
public class ${controllerName}{

    private final ${apiName} ${apiName?uncap_first};

<#if enableSwagger3>
    @Operation(summary = "新增数据")
<#else>
    /**
     * 插入新数据
     * @author ${author}
     * @since ${date}
     * @param model:
    */
</#if>
    @PostMapping("")
    public void insert(@RequestBody @Validated ${modelName} model){
        ${apiName?uncap_first}.insert(model);
    }

<#if primaryColumn?? && (primaryColumn?size == 1)>
    <#if enableSwagger3>
    @Operation(summary = "根据ID删除记录")
    <#else>
    /**
      * 根据ID删除记录
      * @author ${author}
      * @since ${date}
      * @param id:
    */
    </#if>
    @DeleteMapping("/{id}")
    public void deleteById(@PathVariable("id") ${primaryColumn[0].javaType} id){
        ${apiName?uncap_first}.deleteById(id);
    }

    <#if enableMyBatisPlus>
    @Operation(summary = "更新记录")
    <#else>
    /**
      * 根据ID更新记录
      * @author ${author}
      * @since ${date}
      * @param model:
    */
    </#if>
    @PutMapping("/{id}")
    public void update(@PathVariable("id") ${primaryColumn[0].javaType} id,@RequestBody @Validated ${modelName} model){
        model.set${primaryColumn[0].javaFiled?cap_first}(id);
        ${apiName?uncap_first}.updateSelectiveById(model);
    }

    <#if enableMyBatisPlus>
    @Operation(summary = "查询详情")
    <#else>
    /**
      * 根据ID查询记录
      * @author ${author}
      * @since ${date}
      * @param id:
      * @return ${modelPackage}.${modelName}
      */
    </#if>
    @GetMapping("/{id}")
    public ${modelName} getById(@PathVariable("id") ${primaryColumn[0].javaType} id){
        return ${apiName?uncap_first}.selectById(id);
    }

</#if>

}

